package pos.datos;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;



import pos.dominio.Comercio;
import pos.dominio.Evento;


public class JDBCEventoDAO implements IEventoDAO{

	public List<Evento> ObtenerEventos() {
		
		Connection conn = ConnectionManager.getInstance().checkOut();
        PreparedStatement stmt = null;
        List<Evento> searchResults = new LinkedList<Evento>();
        ResultSet result = null;
        
        try {

            String sql = "SELECT * FROM eventos";
            stmt = conn.prepareStatement(sql); 
            stmt.executeQuery();
            result = stmt.executeQuery();

            while (result.next()) {
            
                    Evento temp=new Evento();
                    
                    temp.setNombre(result.getString("nombreEvento"));
                    temp.setGrado(result.getInt("Grado"));
                    temp.setMulta(result.getInt("Multa"));
                    temp.setSalto(result.getBoolean("Salto"));
                    temp.setAtaque(result.getInt("Ataque"));
                    temp.setDefensas(result.getInt("Defensa"));
                    temp.setDatosCompra(new Comercio(result.getInt("datos_Compra_agri"),result.getInt("datos_Compra_arm"),result.getInt("datos_Compra_Indus"),result.getInt("datos_Compra_Cont")));
                    temp.setDatosVenta(new Comercio(result.getInt("datos_Venta_agri"),result.getInt("datos_Venta_arm"),result.getInt("datos_Venta_Indus"),result.getInt("datos_Venta_Cont")));
                    
                    
                    searchResults.add(temp);
            }
        } catch (SQLException e) {
            System.out.println("Message: " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("ErrorCode: " + e.getErrorCode());
        } finally {
            ConnectionManager.getInstance().checkIn(conn);
            try {
                if (result != null)
                    result.close();
                if (stmt != null)
                    stmt.close();
            } catch (SQLException e) {
            }

        }
            return searchResults;
       
	
}

	
	
	

	
}
	
	

	

